/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dvd.view;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
import com.dvd.model.DVDItem;



/**
 *
 * @author 17296375-7
 */
public class ListLibraryServlet extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        
        List dvds = new ArrayList();
        dvds.add(new DVDItem("El regreso de Java","2013","Drama"));
        dvds.add(new DVDItem("El regreso de Java 1","2013","Drama"));
        dvds.add(new DVDItem("El regreso de Java 2","2013","Comedia"));
        
        
        try {
            /*
             * TODO output your page here. You may use following sample code.
             */
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet ListLibraryServlet</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet ListLibraryServlet at " + request.getContextPath() + "</h1>");
            
           
            out.print("<table border='2'>");
            out.print("<tr>");
             out.print("<td> Title </td>");
            out.print("<td> Year </td>");
            out.print("<td> Genre </td>");
            out.print("</tr>");
            
            
            Iterator it =dvds.iterator();
            
            while (it.hasNext()){
            DVDItem item= (DVDItem) it.next();
            out.print("<tr>");
            out.print("<td>" +item.getTitle()+"</td>");
            out.print("<td>" +item.getYear()+"</td>");
            out.print("<td>" +item.getGenre()+"</td>");
            
           
          }
           
            out.print("</table>"); 
            out.println("este el fin de la lista </br>");
            out.println("Nro de registro en al Lista" +dvds.size());
            out.println("</body>");
            out.println("</html>");
        } finally {            
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
